﻿using System;
using Microsoft.AspNetCore.Mvc;

namespace FlashPay.Admin.Controllers
{
    using FlashPay.Entity;
    using FlashPay.Entity.Request.User;
    using FlashPay.Entity.Response.User;
    using FlashPay.Service.Interface;
    using FlashPay.Util;
    using Microsoft.AspNetCore.Http;

    /// <summary>
    /// 系统权限控制器
    /// </summary>
    public class SysAuthController : BaseController
    {
        #region 注入
        /// <summary>
        /// 授权业务接口
        /// </summary>
        private readonly AuthorizeService _authorizeService;

        /// <summary>
        /// 菜单业务接口
        /// </summary>
        private readonly MenuService _menuService;

        /// <summary>
        /// 用户业务接口
        /// </summary>
        private readonly UserInfoService _userInfoService;

        /// <summary>
        /// 注入
        /// </summary>
        /// <param name="menuService"></param>
        /// <param name="authorizeService"></param>
        /// <param name="userInfoService"></param>
        public SysAuthController(IAuthenticate<TicketResponse> _manage, IHttpContextAccessor _accessor, AuthorizeService authorizeService, MenuService menuService, UserInfoService userInfoService) : base(_manage, _accessor)
        {
            _authorizeService = authorizeService;
            _menuService = menuService;
            _userInfoService = userInfoService;
        }
        #endregion

        /// <summary>
        /// 获取权限
        /// </summary>
        /// <param name="authCode">权限码</param>
        [AuthorizeFilter(AuthCode.SysConfig0006)]
        public JsonResult GetPermission(UserPermissionReqeust reqeust)
        {
            var permissions = _userInfoService.GetUserPermission(reqeust);
            return Json(permissions);
        }

        /// <summary>
        /// 获取缓存
        /// </summary>
        /// <param name="authCode">键</param>
        [AuthorizeFilter(AuthCode.SysConfig0006)]
        public JsonResult GetCatche(string key) {

            var response = new JResult<TicketResponse>() {
                Success = true
            };

            try
            {
                response.Data = new MemoryCacheUtil().Get<TicketResponse>(EncryptHelper.deCryptDES(key));
            }
            catch (Exception ex) {
                throw ex;
            }
            return Json(response);
        }
    }
}